package com.yint.http;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import com.yint.http.call.Call;

public abstract class ResultCallback< T >
{
	public Type mType;

	public ResultCallback()
	{
		mType = getSuperclassTypeParameter( getClass() );
	}

	public abstract void onError( Call call, Exception e );

	public abstract void onResponse(Call call, T result, int code);

	public static Type getSuperclassTypeParameter( Class< ? > subclass )
	{
		Type superclass = subclass.getGenericSuperclass();
		if ( superclass instanceof Class )
		{
			throw new RuntimeException( "Missing type parameter." );
		}
		ParameterizedType parameterized = ( ParameterizedType ) superclass;
		return parameterized.getActualTypeArguments()[0];
	}
}
